package com.cn.controller;


import com.cn.config.JsonResult;
import com.cn.config.PageResult;
import com.cn.damain.dto.ReserveQuery;
import com.cn.damain.po.StCertInfo;
import com.cn.service.impl.StCertService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  店铺管理前端控制器
 * </p>
 *
 * @since 2023-12-19
 */
@RestController
@RequestMapping("/certInfo")
@RequiredArgsConstructor
public class StCertController {

    @Resource
    StCertService stCertService;

    @PostMapping("/list")
    public JsonResult listData(@RequestBody ReserveQuery pageQuery) {
        PageResult<StCertInfo> result = stCertService.listDataPage(pageQuery);
        return JsonResult.result(result);
    }

    @PostMapping("/add")
    public JsonResult add(@RequestBody StCertInfo data) {
        try {
            stCertService.saveData(data);
            return JsonResult.result("成功！");
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.failResult(e.getMessage());
        }
    }

    @PostMapping("/update")
    public JsonResult update(@RequestBody StCertInfo data) {
        try {
            stCertService.editData(data);
            return JsonResult.result("成功！");
        }catch (Exception e){
            return JsonResult.failResult(e.getMessage());
        }
    }

    @PostMapping("/delete")
    public JsonResult delete(@RequestBody StCertInfo data) {
        try {
            stCertService.delData(data.getId());
            return JsonResult.result("成功！");
        }catch (Exception e){
            return JsonResult.failResult(e.getMessage());
        }
    }
}
